<!--conf
<sample>
              <product version="1.4" edition="pro"/>
                     <modifications>
                            <modified date="070101"/>
                     </modifications>
               </sample>
 --> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Configuring  combo boxes on the fly</title>
	



</head>

<body>
<link rel='STYLESHEET' type='text/css' href='../common/style.css'>
<table cellspacing="0" cellpadding="0" class="sample_header" border="0">
	<tr valign="middle">
		<!-- COMPONENT ICON -->
		<td width="40" align="center"><img src="../common/dhtmlxgrid_icon.gif" border="0"></td>
		<!-- COMPONENT NAME -->
		<td width="150" align="left" nowrap="true">Sample: dhtmlxGrid</td>
		<!-- SAMPLE TITLE -->
		<td width="0" align="left" nowrap><b>Configuring  combo boxes on the fly</b></td>
		<!-- LINK TO COMPONENT PAGE -->
		<td width="0" align="right"><a href="http://www.dhtmlx.com/docs/products/dhtmlxGrid/index.shtml">dhtmlxGrid main page</a></td>
		<!-- CLOSE BUTTON -->
		<td width="50"><div class="sample_close"><a href="javascript:void(0);" onclick="self.close();"><img src="../common/sample_close.gif" width="14" height="14" border="0" alt="X"></a></div></td>
	</tr>
</table>
	
	
	<p>
       The comboboxes have different values for even and uneven rows. (the Shipping column)
	</p>
	<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxgrid.css">
	<script  src="../../codebase/dhtmlxcommon.js"></script>
	<script  src="../../codebase/dhtmlxgrid.js"></script>
	<script  src="../../codebase/dhtmlxgridcell.js"></script>	
	
				<div id="gridbox" width="600px" height="250px" style="background-color:white;"></div>
			
<br>
<div class='sample_code'><div class="hl-main"><pre><span class="hl-code"> 
</span><span class="hl-brackets">&lt;</span><span class="hl-reserved">div</span><span class="hl-code"> </span><span class="hl-var">id</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">gridbox</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-var">width</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">100%</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-var">height</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">250px</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-var">style</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">background-color:white;overflow:hidden</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">&gt;</span><span class="hl-brackets">&lt;/</span><span class="hl-reserved">div</span><span class="hl-brackets">&gt;</span><span class="hl-code">
</span><span class="hl-brackets">&lt;</span><span class="hl-reserved">script</span><span class="hl-brackets">&gt;</span><span class="hl-code"><div class="hl-main"><pre><span class="hl-code"> 
    </span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">myf</span><span class="hl-brackets">(</span><span class="hl-identifier">stage</span><span class="hl-code">,</span><span class="hl-identifier">id</span><span class="hl-code">,</span><span class="hl-identifier">index</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-reserved">var</span><span class="hl-code"> </span><span class="hl-identifier">ind</span><span class="hl-code">=</span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">getRowIndex</span><span class="hl-brackets">(</span><span class="hl-identifier">id</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-brackets">(</span><span class="hl-identifier">index</span><span class="hl-code">==</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">&amp;&amp;</span><span class="hl-brackets">(</span><span class="hl-identifier">stage</span><span class="hl-code">==</span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-comment">//</span><span class="hl-comment">start edit Shipping column</span><span class="hl-comment"></span><span class="hl-code">
            </span><span class="hl-brackets">{</span><span class="hl-code">
            </span><span class="hl-reserved">var</span><span class="hl-code"> </span><span class="hl-identifier">combo</span><span class="hl-code">=</span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">getCombo</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">;
            </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">ind</span><span class="hl-code">%</span><span class="hl-number">2</span><span class="hl-code">==</span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">                      </span><span class="hl-comment">//</span><span class="hl-comment">for even rows</span><span class="hl-comment"></span><span class="hl-code">
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">save</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;                   </span><span class="hl-comment">//</span><span class="hl-comment">save initial state</span><span class="hl-comment"></span><span class="hl-code">
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">remove</span><span class="hl-brackets">(</span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-code">;
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">remove</span><span class="hl-brackets">(</span><span class="hl-number">2</span><span class="hl-brackets">)</span><span class="hl-code">;
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">remove</span><span class="hl-brackets">(</span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-code">;
                </span><span class="hl-brackets">}</span><span class="hl-code">
                </span><span class="hl-reserved">else</span><span class="hl-brackets">{</span><span class="hl-code">
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">save</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;                   </span><span class="hl-comment">//</span><span class="hl-comment">save initial state</span><span class="hl-comment"></span><span class="hl-code">
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">remove</span><span class="hl-brackets">(</span><span class="hl-number">4</span><span class="hl-brackets">)</span><span class="hl-code">;
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">remove</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">;
                </span><span class="hl-identifier">combo</span><span class="hl-code">.</span><span class="hl-identifier">remove</span><span class="hl-brackets">(</span><span class="hl-number">6</span><span class="hl-brackets">)</span><span class="hl-code">;
                </span><span class="hl-brackets">}</span><span class="hl-code">
            </span><span class="hl-brackets">}</span><span class="hl-code">
 
        </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-brackets">(</span><span class="hl-identifier">index</span><span class="hl-code">==</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">&amp;&amp;</span><span class="hl-brackets">(</span><span class="hl-identifier">stage</span><span class="hl-code">==</span><span class="hl-number">2</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">             </span><span class="hl-comment">//</span><span class="hl-comment">for finishing edit</span><span class="hl-comment"></span><span class="hl-code">
           </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">getCombo</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">restore</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;        </span><span class="hl-comment">//</span><span class="hl-comment">restore combo state</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-reserved">true</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-identifier">mygrid</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">dhtmlXGridObject</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">gridbox</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">setImagePath</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">../../codebase/imgs/</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">attachEvent</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">onEditCell</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-identifier">myf</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">loadXML</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">gridH.xml</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;</span></pre></div></span><span class="hl-brackets">&lt;/</span><span class="hl-reserved">script</span><span class="hl-brackets">&gt;</span></pre></div></div>

<script>
    function myf(stage,id,index){
        var ind=mygrid.getRowIndex(id);
        if ((index==5)&&(stage==0))//start edit Shipping column
            {
            var combo=mygrid.getCombo(5);
            if (ind%2==1){                      //for even rows
                combo.save();                   //save initial state
                combo.remove(1);
                combo.remove(2);
                combo.remove(3);
                }
                else{
                combo.save();                   //save initial state
                combo.remove(4);
                combo.remove(5);
                combo.remove(6);
                }
            }

        if ((index==5)&&(stage==2))             //for finishing edit
           mygrid.getCombo(5).restore();        //restore combo state
        return true;
    }
	mygrid = new dhtmlXGridObject('gridbox');
	mygrid.setImagePath("../../codebase/imgs/");
	mygrid.attachEvent("onEditCell",myf);
	mygrid.loadXML("gridH.xml");
</script>

<!-- FOOTER -->
<table callspacing="0" cellpadding="0" border="0" class="sample_footer"><tr><td style="padding-left: 8px;">&copy; <a href="http://www.dhtmlx.com">DHTMLX LTD</a>. All rights reserved</td></tr></table>
<!-- FOOTER -->

</body>
</html>
